/**
 * Copyright (C) 2013 AirChina
 *
 * @description:
 * @version:v1.0.0
 */
package com.china.itapi.common.redis;

import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;

import com.china.itapi.common.CommonConfig;

import redis.clients.jedis.Jedis;


/**
 * @Description:
 * @author:larry
 * @Created:2013-10-28下午12:08:51
 */
public class CacheManager {

	private static final Map<String, CacheClient> clients = new HashMap<String, CacheClient>();

	public static final CacheClient commonCache = CacheManager.getCacheClient(CommonConfig.getCommonCacheServer());

	/**
	 * @Description:获取redis客户端
	 * @param servers
	 *            格式：localhost:6379
	 * @return
	 * @throws
	 * @Created:larry 2013-10-28下午5:18:29
	 */
	public static CacheClient getCacheClient(String server) {
		CacheClient client = clients.get(server);
		if(client == null){
			JedisProxy proxy = new JedisProxy(server.split(","));
			client = (CacheClient) Proxy.newProxyInstance(Jedis.class.getClassLoader(), new Class<?>[] { CacheClient.class }, proxy);
			clients.put(server, client);
		}
		return client;
	}
	
}
